From: Andrew Dodd Date: Tue, 17 Dec 2024 01:37:35 +0000 (+1100) Subject: luci: Make password reveal work with passsword managers X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22/%22https:/collectd.org/%22?a=commitdiff_plain;h=fc8ad20bbb7d7df16aeda37e8c3bf8495bedc6c3;p=project%2Fluci.git luci: Make password reveal work with passsword managers Password managers (like LastPass etc) tend to add additional elements into the DOM for their own context menus. If this happens between the hide/reveal button and the password input, then the logic to reveal the password breaks. This change updates the onclick handler to look for the first `` element with the class `password-input` that is under the parent of the toggle button, and then to toggle the password/text type on that element. This change deliberately only updates the main ui.js file, not any application files. Signed-off-by: Andrew Dodd --- diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index f0ea264bd4..def3eb13d3 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -368,7 +368,7 @@ const UITextfield = UIElement.extend(/** @lends LuCI.ui.Textfield.prototype */ { 'id': this.options.id ? `widget.${this.options.id}` : null, 'name': this.options.name, 'type': 'text', - 'class': this.options.password ? 'cbi-input-password' : 'cbi-input-text', + 'class': `password-input ${this.options.password ? 'cbi-input-password' : 'cbi-input-text'}`, 'readonly': this.options.readonly ? '' : null, 'disabled': this.options.disabled ? '' : null, 'maxlength': this.options.maxlength, @@ -384,8 +384,15 @@ const UITextfield = UIElement.extend(/** @lends LuCI.ui.Textfield.prototype */ { 'title': _('Reveal/hide password'), 'aria-label': _('Reveal/hide password'), 'click': function(ev) { - const e = this.previousElementSibling; - e.type = (e.type === 'password') ? 'text' : 'password'; + // DOM manipulation (e.g. by password managers) may have inserted other + // elements between the reveal button and the input. This searches for + // the first inside the parent of the